package cn.edu.imnu.controller.web;

import common.model.DataBootstrapTable;
import common.model.ResponseModelBootstrapTable;
import cn.edu.imnu.model.WordProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.edu.imnu.service.WordPropertyService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @author ranhongmin--2018/3/10
 * Description:
 */
@Controller
@RequestMapping("wordPropertyAction")
public class WordPropertyController {
	@Resource
	private WordPropertyService propertyService;

	/**
	 * main
	 *
	 * @param request
	 * @param dataBootstrapTable
	 * @return
	 */
	@RequestMapping("main.json")
	@ResponseBody
	public ResponseModelBootstrapTable main(HttpServletRequest request, DataBootstrapTable dataBootstrapTable) {
		return propertyService.main(dataBootstrapTable);
	}

	/**
	 * add
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("add.json")
	@ResponseBody
	public ResponseModelBootstrapTable add(HttpServletRequest request, WordProperty info) {
		return propertyService.doAction(info, "1");
	}


	/**
	 * update
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("update.json")
	@ResponseBody
	public ResponseModelBootstrapTable update(HttpServletRequest request, WordProperty info) {
		return propertyService.doAction(info, "2");
	}

	/**
	 * del
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("del.json")
	@ResponseBody
	public ResponseModelBootstrapTable del(HttpServletRequest request, WordProperty info) {
		return propertyService.doAction(info, "3");
	}

	/**
	 * 跟组词条id获取词条属性
	 *
	 * @param request
	 * @param wordId
	 * @return
	 */
	@RequestMapping("getPropertyByWordId.json")
	@ResponseBody
	public ResponseModelBootstrapTable getPropertyByWordId(HttpServletRequest request, String wordId) {
		return propertyService.getPropertyByWordId(wordId);
	}
}
